perf: reduce snapshot read memory retention#985
Merged
Conversation
Contributor
WASM Size Report
|
65d6c6e to
6f0cbaa
Compare
zxch3n
added a commit
that referenced
this pull request
Jun 17, 2026
* fix: recover two per-op editing slowdowns regressed since 1.11 Both are constant-factor regressions on the per-op (auto-commit) editing path introduced by the lazy-snapshot work in #985, found while bisecting current HEAD against the 1.11.1 release. 1. map/list/movable-list insert: ensure_no_regular_container_value heap-allocated a Vec on every insert, even for scalar values (the common case). Add a scalar fast-path that skips the allocation and traversal. `map create 10^4 key`: ~19.4ms -> ~10.7ms. 2. text insert/delete: the per-op bounds-check len()/len_unicode()/ len_utf16() took two DocState locks (decoded-check, then query). Consolidate into one DocState::get_text_len taking a single lock + container-store lookup, preserving the lazy-snapshot memory behavior (a still-lazy container reads cached length metadata without materializing the richtext state). `bench_text B4 apply`: ~389ms -> ~352ms. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * chore: sync Cargo.lock with loro-wasm 1.13.4 version bump Lockfile update to match the crates/loro-wasm Cargo.toml version bump that landed via the main merge (chore: version packages). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix: read cached byte length for PosType::Bytes text len Addresses a review finding on the per-op text length consolidation: the PosType::Bytes branch of DocState::get_text_len built the full plain string via get_value_by_idx().as_string().len(), so insert_utf8/delete_utf8 bounds checks on an already-decoded text became O(text length) per op (the old code read cached byte-length metadata in the decoded case). Add a text_utf8_len store helper mirroring text_unicode_len/text_utf16_len: - decoded state reads the O(1) cached byte length (RichtextState::len_utf8 = root_cache().bytes) - a still-lazy container reads the byte length from the already-materialized text value string (O(1) str::len), preserving the no-force-decode behavior Also route the public TextHandler::len_utf8 through the same single-lock helper; it had the same has_decoded_state double-lock + string-construction pattern. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This was referenced Jun 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
toJSONandloro-mirrorstyle reads.Measurements
Using the 32 MB fixture probe after exporting/importing a snapshot:
toJSON()then dropping JSON: 41.81 MB -> 25.58 MBTradeoff: repeated full read-only traversals decode again instead of reusing retained decoded values. Current release probe timings were roughly
toJSON72 ms, mirror shallow 79/59 ms, and mirror schema root 143/131 ms.Validation
cargo check -p loro-internalcargo test -p loro-internal handler --libcargo test -p loro-internal map --libcargo test -p loro-internal list --libcargo test -p loro-internal snapshot --libcargo test -p loro-internal richtext --libgit diff --check